<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib uri="/WEB-INF/tlds/att.tld" prefix="att"%>
<html>
<head>
<meta name="decorator" content="moduleEdit" />
<script src="${staticPath}/lib/jquery/1.10.2/jquery.js" type="text/javascript"></script>
<script src="${staticPath}/lib/ztree/3.5/js/jquery.ztree.all-3.5.js" type="text/javascript"></script>
<link rel="stylesheet" href="${staticPath}/lib/ztree/3.5/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript">
var rootId=0;
var _treeNode;
$(function(){
	//加载树
	loadTree();
});
var log, className = "dark", startTime = 0, endTime = 0, perCount = 100, perTime = 100;
//树
var cateTree;
//加载树
function loadTree(){
	
	var setting = {
			view : {
				selectedMulti : false,
				fontCss : getFont,
				nameIsHTML : true
			},
			edit : {
				drag:false,
				enable: true,
				showRemoveBtn: false,
				showRenameBtn: false
			},
			data : {
				simpleData : {
					enable : true
				}
			},
			callback : {
				onClick : zTreeOnLeftClick
			}
		};
		$.get("${contextPath}/biz/brand/cate/getCateTreeData", function(data) {
			zNodes = eval("(" + data + ")");
			$.fn.zTree.init($("#cateTree"), setting, zNodes);
		});
	};
	function getFont(treeId, node) {
		return node.font ? node.font : {};
	}
	
	//左击
	function zTreeOnLeftClick(event, treeId, treeNode){
		if(treeNode.level==0){
			$('#add').attr("disabled", "disabled");
		}else{
			$('#add').removeAttr("disabled");
		}
		_treeNode=treeNode; 
		var vNode = treeNode;
		var arr = new Array(); 
		if(vNode!=null)
		{
			for(var i=1;i<= treeNode.level;i++)
			{
				arr[i-1]=vNode.name;
				vNode = vNode.parent;
				if(vNode==null)
				{
				 break;
				}
			}
		}
		var names="";
		for(var i=arr.length-1;i>=0;i--)
		{
			names += arr[i]+"/";
		}
		_showCateName = names.substring(0,names.length-1) ;
	};
	
	//展开收起
	function treeExpandAll(type){
		cateTree = $.fn.zTree.getZTreeObj("cateTree");
		cateTree.expandAll(type);
	};
	
	//选择资源节点。
	function getSelectNode(){
		cateTree = $.fn.zTree.getZTreeObj("cateTree");
		var nodes  = cateTree.getSelectedNodes();
		var node   = nodes[0];
		return node;
	}
	
	//刷新
	function reFresh(){
		loadTree();
	};
	function funform(url,target)
	{
		var treeid;
		if(_treeNode!=null){
			treeid=_treeNode.id;
		}
		
		if(treeid==""||typeof(treeid)=="undefined"){
			alert("请选择上级节点");
		}else{
			window.open(url+"?cateId="+treeid+"&cate.cateName="+_showCateName,target);
			//location.href=url+"?parentNo="+treeid;
		}
	}
</script>
<style type="text/css">
	.ztree li span.button.switch.level0 {visibility:hidden; width:1px;}
	.ztree li ul.level0 {padding:0; background:none;}
	.tree-toolbar {
	padding-left: 2px;
	border-top: none;
	border-bottom: none;
	border: 1px #FFFFFF solid;
	height: 21px;
	padding-top: 4px;
	font-size: 14px;
	}
	.tree-toolbar a {
		text-decoration: none;
		color: blue;
		float: left;
		margin-left: 5px;
		color: inherit;
	}
</style>
</head>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col-xs-12">
				<div class="panel panel-default">
				  <div class="panel-heading">
				  <tags:message content="${message}"/>
				    <h3 class="panel-title">
				    	品类管理<span class="glyphicon &{icon}"></span>
				    </h3>
				  </div>
					<div class="tree-toolbar tree-title">
						<div><a id="treeFresh" href="javascript:reFresh();">刷新</a></div>
						<div><a id="treeExpandAll" href="javascript:treeExpandAll(true)">展开</a></div>
						<div><a id="treeCollapseAll" href="javascript:treeExpandAll(false)">收起</a></div>
					</div>
				  <ul id="cateTree" class="ztree" ></ul>
				</div>			
			</div>
			<div class="form-group">
				  <div class="col-sm-offset-5 col-sm-10">
				    <button id="add"  class="btn btn-primary" role="button" onclick="funform('${contextPath}/biz/brand/brandcate/apply','_self');">确认</button>
					<a class="btn btn-default" role="button" href="javascript:void(0)" onclick="history.go(-1)">取消</a>
				  </div>
			</div>
		</div>
	</div>
</body>
</html>